<?php

class NComponentHelper {



static function getBaseUrl(){
	$componentName = NRequest::getVar("component");
	return NURI::base()."/components/$componentName";
}
static function getBaseDir(){
	$componentName = NRequest::getVar("component");
	return NPATH::base()."/components/$componentName";
}
function renderComponent($name = null, $params = array())
	{
		global $mainframe, $option;

		if(empty($name)) {
			// Throw 404 if no component
			//NError::raiseError(404, NText::_("Component Not Found"));
			//return;
			$name='com_default';
		}

	

		// Build the component path
		$name = preg_replace('/[^A-Z0-9_\.-]/i', '', $name);
		

		// Define component path
		if (!$mainframe->isAdmin()) 
		define( 'NPATH_COMPONENT',				ROOT_DIR.DS.'components'.DS.$name);
		else 
		define( 'NPATH_COMPONENT',				ADMIN_ROOT_DIR.DS.'components'.DS.$name);
			
		//echo NPATH_COMPONENT;
		
		// get component path
		
			$path = NPATH_COMPONENT.DS.'index.php';
		//echo $path;
		// Handle template preview outlining
		$contents = null;

		// Execute the component
		
		ob_start();
		require_once $path;
		$contents = ob_get_contents();
		ob_end_clean();

		$_doc=NFactory::getDocument();
		$contents = $_doc->_parseTemplate($contents);

		return $contents;
	}

}
?>